feat(log): add stopChainOnFailure handler option - #10578
Alexandros-Pallis wants to merge 1 commit into
Conversation
neznaika0
left a comment
There was a problem hiding this comment.
It looks logical, but now we practically have no option to stop the handler - result is always returned to continue processing.
Perhaps, after these changes, stopping is not required at all, in which case, what’s the point of the new constants?
michalsn
left a comment
There was a problem hiding this comment.
I believe this behavior should be configurable via Config\Logger, and preferably the default behavior should remain the same as it is now.
|
Thanks for picking this up. Looking closer I think the interface change isn't what fixes the bug. TLDR: A change to The fix is the built-in handlers no longer returning the "stop" signal on a write failure. That works with the existing Building on @michalsn's suggestion, I'd propose keeping
Handlers should fall back to For tests, please add A rebase onto |
|
I also agree that going with the config solution is the way to go. I will change the implementation to match what is described above. One suggestion i have is the naming of the config, in my opinion 'stopChainOnFailure' is a bit more descriptive on the purpose of this option. Is it okay if i name it this way or keep 'stopOnFailure' as suggested initially? Thanks everyone for the feedback! |
A failed write in FileHandler or ErrorlogHandler returns false, which stops the handler chain, so a fallback handler configured after it never logs the message. Setting 'stopChainOnFailure' => false in the handler config makes a failed write return true, letting the remaining handlers run. Defaults to true, so existing configs and HandlerInterface are unchanged.
|
Hi there, @Alexandros-Pallis! 👋 It looks like this pull request does not follow our template:
Please update the description to follow the template. The |
|
Based on above discussion i have adjusted the direction of this PR and moved towards a config based solution. |
80803b5 to
d2606ef
Compare
This PR adds a per-handler option,
stopChainOnFailure, forFileHandlerandErrorlogHandler, set in the handlersettings of
Config\Logger:true(default, also when the key is missing): a failed write returnsfalseand stops the chain. Same as today. -false: a failed write returnstrue, so the handlers after it still run.The option is read in
BaseHandler, so custom handlers extending it can use it as well. Custom handlers can still returnfalseto stop the chain on purpose.There is no breaking change:
HandlerInterface::handle()still returnsbool, andLogger::log()is not modified.app/Config/Logger.phpfiles work unchanged.BaseHandlergains a new protected property,bool $stopChainOnFailure.Project files:
app/Config/Logger.php:stopChainOnFailureadded to theFileHandlerblock and to the commentedErrorlogHandlerblock. The@vartype of$handlersnow includesbool(same inMockLogger).Tests:
LoggerTest: aFileHandlerpointed at a missing directory followed byTestHandler. With the default, the second handler does not log. With'stopChainOnFailure' => false, it does.FileHandlerTestandErrorlogHandlerTest: default, explicittrue, andfalseon a failed write.FileHandlerTestalso covers a successful write withfalse.User guide:
general/logging.rst: new section "Stopping the Handler Chain on Failure" with an example.v4.8.0.rst: entry under Enhancements.upgrade_480.rst:app/Config/Logger.phplisted under the config content changes.Checklist: